package com.kgc.scd.service.impl;

import com.kgc.scd.bean.Product;
import com.kgc.scd.mapper.ProductMapper;
import com.kgc.scd.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created On : 2022/6/16.
 * <p>
 * Author     : nainai
 * <p>
 * Description: 商品业务接口实现类
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired(required = false)
    private ProductMapper productMapper;

    @Override
    public Integer queryProductStock(String proId) {
        return productMapper.selectByPrimaryKey(proId).getProStock();
    }

    @Override
    public Product queryProductById(String proId) {
        return productMapper.selectByPrimaryKey(proId);
    }

    @Override
    public boolean addProductStock(String proId, Integer stock) {
        Product product = Product.builder()
                .proStock(queryProductById(proId).getProStock() + stock)
                .proId(proId)
                .build();
        return productMapper.updateByPrimaryKeySelective(product) > 0;
    }
}
